package com.study.lihan.letcode;

import com.study.lihan.letcode.util.Util;

/*
*https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/
* */
public class My34 {
    public static void main(String[] args) {

        int[] nums = {5,7,7,8,8,10};
        int target =6;
        Solution34 solution34 = new Solution34();
        int[] result = solution34.mysearchRange(nums,target);
        Util.printArr(result);
    }
}


class Solution34 {
    public int[] mysearchRange(int[] nums, int target) {
        int[] result = {-1,-1};
        if(nums==null || nums.length==0) return result;
        int lastIndex = 0;
        for(int firstIndex =0; lastIndex<nums.length; lastIndex++){
   //快指针第一次相同，记录nums【0】
            if(nums[lastIndex] == target){
                result[0] = firstIndex;
                continue;
            }
            firstIndex++;
            //快指针相同后，第一次不同
        if(lastIndex-1>-1 && nums[lastIndex-1] == target && nums[lastIndex] != target)break;
        }
        if(result[0] !=-1) result[1] = lastIndex-1;
        return  result;
    }
    public int[] searchRange(int[] nums, int target) {
     return  null;
    }
}